 package com.gmrz.uaf.protocol.v1.json;
 
 import com.google.gson.JsonDeserializationContext;
 import com.google.gson.JsonDeserializer;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonParseException;
 import com.google.gson.JsonSerializationContext;
 import com.google.gson.JsonSerializer;
 import com.gmrz.uaf.protocol.v1.processor.exception.InvalidUAFMessageException;
 import com.gmrz.uaf.protocol.v1.processor.exception.UAFErrorCode;
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
 
 public class ConstantsAdapter
   implements JsonSerializer, JsonDeserializer
 {
   private Method mget = null;
   private Method mfor = null;
 
   public ConstantsAdapter(Class c) throws InvalidUAFMessageException
   {
     try {
       this.mfor = c.getDeclaredMethod("forName", String.class);
       this.mfor.setAccessible(true);
 
       this.mget = c.getDeclaredMethod("getName");
       this.mget.setAccessible(true);
     }
     catch (Exception ex) {
       throw new InvalidUAFMessageException(UAFErrorCode.PROTOCOL_INVALID_UAF_RESPONSE, ex);
     }
   }
 
   public Object deserialize(JsonElement json, Type type, JsonDeserializationContext ctxt) throws JsonParseException
   {
     try
     {
       return this.mfor.invoke(null, json.getAsString());
     } catch (Exception e) {
       e.printStackTrace();
     }
 
     return null;
   }
 
   public JsonElement serialize(Object src, Type type, JsonSerializationContext ctxt)
   {
     try
     {
       String name = (String)this.mget.invoke(src);
       return ctxt.serialize(name);
     } catch (Exception e) {
       e.printStackTrace();
     }
 
     return null;
   }
 }
